/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.Shop.service;

import com.Shop.beans.Chack;
import com.Shop.beans.Document;
import com.Shop.beans.Download;
import com.Shop.beans.OdbsException;
import com.Shop.beans.Pager;
import com.Shop.beans.Report;
import com.Shop.beans.User;
import com.Shop.dao.ChackDao;
import com.Shop.dao.CollectionDao;
import com.Shop.dao.CommentDao;
import com.Shop.dao.DocumentDao;
import com.Shop.dao.DownloadDao;
import com.Shop.dao.ReportDao;
import com.Shop.dao.UserDao;
import com.Shop.utils.MD5;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.web.multipart.MultipartFile;

/**
 *
 * @author cjh
 */
public class UserService {

    private UserDao userDao;
    private DocumentDao documentDao;
    private ChackDao chackDao;
    private CollectionDao collectionDao;
    private CommentDao commentDao;
    private DownloadDao downloadDao;
    private ReportDao reportDao;

    public CommentDao getCommentDao() {
        return commentDao;
    }

    public void setCommentDao(CommentDao commentDao) {
        this.commentDao = commentDao;
    }

    public DownloadDao getDownloadDao() {
        return downloadDao;
    }

    public void setDownloadDao(DownloadDao downloadDao) {
        this.downloadDao = downloadDao;
    }

    public ReportDao getReportDao() {
        return reportDao;
    }

    public void setReportDao(ReportDao reportDao) {
        this.reportDao = reportDao;
    }

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public DocumentDao getDocumentDao() {
        return documentDao;
    }

    public void setDocumentDao(DocumentDao documentDao) {
        this.documentDao = documentDao;
    }

    public ChackDao getChackDao() {
        return chackDao;
    }

    public void setChackDao(ChackDao chackDao) {
        this.chackDao = chackDao;
    }

    public CollectionDao getCollectionDao() {
        return collectionDao;
    }

    public void setCollectionDao(CollectionDao collectionDao) {
        this.collectionDao = collectionDao;
    }

    /* ************************************************************************
     *
     * 下面开始写UserService的代码
     *
     *************************************************************************/
    public void addUser(String phone,String password,String nickname){
       User user =new User();
       user.setPhone(phone);
//       System.out.println(phone);
       user.setPassword(password);
       user.setNickname(nickname);
       userDao.addUser(user);
    }
    
    /**
     * 处理用户登录
     *
     * @param key 用户登录的账户，可以是电话号码或者邮箱
     * @param password 用户密码
     * @return 登陆成功后用户的实例
     */
    
    public User loginUser(String phone,String password){
        User user=userDao.loginUser(phone, password);
        if(user==null){
            System.out.println("用户密码不正确");
            return null;
        }
        return user;
    }
    
    public User loadUser(int id){
        User user =userDao.loadUser(id);
        if(user==null){
            System.out.println("用户不存在!");
            return null;
        }
        return user;
    }
    
    public User loadUserByPhone(String phone){
        User user =userDao.loadUserByPhone(phone);
        if(user==null){
            System.out.println("用户不存在!");
            return null;
        }
        return user;
    }
    
    public void deleteUser(int id){
        userDao.deleteUser(id);
    }
    
    public void updateUser(User user){
        userDao.updateUser(user);
    }
    

   
    
    
   
}
